package com.lsx143.wordcount.day10;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import java.time.ZoneOffset;

public class Flink_EventTime_DDL {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        tEnv.getConfig().setLocalTimeZone(ZoneOffset.ofHours(0));
        tEnv.executeSql("create table sensor(" +
                "   id string, " +
                "   ts bigint, " +
                "   vc int, " +
                "   et as TO_TIMESTAMP_LTZ(ts, 3), " +
                "   watermark for et as et - interval '3' second " +
                ")with(" +
                "   'connector'='filesystem', " +
                "   'path'='input/sensor.txt', " +
                "   'format'='csv' " +
                ")");
        TableResult tableResult = tEnv.executeSql("select * from sensor");
        tableResult.print();
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

